package com.tushu.view.admin;

import com.tushu.dao.AdminDao;

import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.Color;
import java.awt.Font;

public class DataCollection extends JPanel {

	private AdminDao adminDao=new AdminDao();

	String sql1 = "SELECT COUNT(*) sum  FROM tb_student\n";
	String sql2 = "SELECT COUNT(*) count FROM tb_book\n";
	String sql3 = "SELECT SUM(num) FROM tb_book";
	String sql4="SELECT COUNT(*) FROM tb_lend l WHERE l.`status`=\"未还\"";
	String sql5 = "SELECT COUNT(*) FROM tb_lend";


	JLabel jt1,jt2,jt3,jt4,jt5;

	/**
	 * Create the panel.
	 */
	public DataCollection() {
		setLayout(null);

		JLabel lblNewLabel = new JLabel("读者数量：");
		lblNewLabel.setBounds(68, 55, 87, 15);
		add(lblNewLabel);

		JLabel lblNewLabel_1 = new JLabel("书籍种类：");
		lblNewLabel_1.setBounds(307, 55, 70, 15);
		add(lblNewLabel_1);

		JLabel lblNewLabel_2 = new JLabel("库存总数：");
		lblNewLabel_2.setBounds(68, 116, 70, 15);
		add(lblNewLabel_2);

		JLabel lblNewLabel_3 = new JLabel("已借出数量：");
		lblNewLabel_3.setBounds(307, 116, 87, 15);
		add(lblNewLabel_3);

		JLabel lblNewLabel_2_1 = new JLabel("待还数量：");
		lblNewLabel_2_1.setBounds(68, 169, 102, 15);
		add(lblNewLabel_2_1);

		jt1 = new JLabel("");
		jt1.setFont(new Font("宋体", Font.PLAIN, 15));
		jt1.setForeground(Color.RED);
		jt1.setBounds(134, 55, 58, 15);
		add(jt1);

		jt2 = new JLabel("");
		jt2.setFont(new Font("宋体", Font.PLAIN, 15));
		jt2.setForeground(Color.RED);
		jt2.setBounds(369, 55, 58, 15);
		add(jt2);

		jt3 = new JLabel("");
		jt3.setFont(new Font("宋体", Font.PLAIN, 15));
		jt3.setForeground(Color.RED);
		jt3.setBounds(134, 116, 58, 15);
		add(jt3);

		jt4 = new JLabel("");
		jt4.setFont(new Font("宋体", Font.PLAIN, 15));
		jt4.setForeground(Color.RED);
		jt4.setBounds(379, 116, 58, 15);
		add(jt4);

		jt5 = new JLabel("");
		jt5.setFont(new Font("宋体", Font.PLAIN, 15));
		jt5.setForeground(Color.RED);
		jt5.setBounds(134, 169, 58, 15);
		add(jt5);
		setData();
	}

	public void setData(){
		jt1.setText(String.valueOf(adminDao.getCount(sql1)));
		jt2.setText(String.valueOf(adminDao.getCount(sql2)));
		jt3.setText(String.valueOf(adminDao.getCount(sql3)));
		jt4.setText(String.valueOf(adminDao.getCount(sql4)));
		jt5.setText(String.valueOf(adminDao.getCount(sql5)));
	}
}
